home *** CD-ROM | disk | FTP | other *** search
- #pragma once
- //
- // skip_spaces just does what it says. It skips spaces, tabs and the like,
- // but no NEWLINES on the stream mentioned. It returns the character which
- // stops the skipping. The character returned is put back into the input
- // stream.
- //
- char skip_spaces( istream &destroom);
- //
- // skip_till skips all chars up to the next occurrence of theLetter
- // or theString
- //
- void skip_till( istream &destroom, const char theLetter);
- void skip_till( istream &destroom, const char *theString);
- //
- // copy_till copies chars from input to output up to but not including
- // the next char
- //
- void copy_till( istream &is, ostream &os, const char theLetter);
- //
- // skip_over_newline skips all chars up to and including the next newline
- //
- void skip_over_newline( istream &destroom);
- //
- // skip_till_digit skips all chars up to but not including the next digit
- // skip_till_numberstart skips all characters up to but not including the
- // next (possible) start of a number, i.e. either a digit or a '-' or '+'.
- // is_possible_numberstart is an auxiliary function to test this.
- //
- void skip_till_digit( istream &destroom);
- void skip_till_numberstart( istream &destroom);
-
- inline int is_possible_numberstart( const char letter)
- {
- return( isdigit( letter) || (letter == '+') || (letter == '-'));
- }
-
- #define min( a, b) (((a) < (b)) ? (a) : (b))
- #define max( a, b) (((a) > (b)) ? (a) : (b))
-
- inline char *strdup( const char *string)
- {
- char *result = new char[ strlen( string) + 1];
- (void)strcpy( result, string);
- return result;
- }
- //
- // 920224: The phrase
- //
- // assert( (an_int >= 0) && (an_int < maxrange));
- //
- // is used (and executed, for instance in beeld::operator[])
- // fairly frequently. Not all compilers will know this to be equivalent to
- //
- // assert( (unsigned int)an_int < maxrange);
- //
- // Therefore we define a function which knows of this equivalence.
- // It remains to be seen whether any performance is gained by this trick,
- // but I think 'a normal compiler' would generate faster code for it.
- // (fysae gives an increase of about 10%)
- //
- inline int range_check( int iks, int maxrange)
- {
- return( (unsigned int)iks < (unsigned int)maxrange);
- }
-
- #define assert_range( iks, maxrange) assert( range_check( iks, maxrange))
- //
- // a general constant used to indicate zero-ness in numerical calculations:
- //
- #define vrijwel_niets 1E-6
-
- inline int bijnanul( const double number)
- {
- return ((fabs( number) < vrijwel_niets));
- }
- //
- // 950506: some constants
- //
- const double one_pi = 3.14159265359;
- const double two_pi = 2.0 * 3.14159265359;
- const double two_over_pi = 2.0 / 3.14159265359;
- //
- // 950614: conversions between degrees and radians.
- // Both are implemented using a multiplication since
- // multipliactions are (on most architectures) faster than divisions.
- //
- const double _180_over_pi = 180.0 / 3.14159265359;
- const double pi_over_180 = 3.14159265359 / 180.0;
-
- double RadiansToDegrees( double rads);
- double DegreesToRadians( double degs);
-
- inline double RadiansToDegrees( double rads)
- {
- return rads * _180_over_pi;
- }
-
- inline double DegreesToRadians( double degs)
- {
- return degs * pi_over_180;
- }
-